package com.jiuzhou.guanwang.jzcp.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.fragment.TeamRankDetailFragment;

public class TeamRankActivity extends AppCompatActivity implements View.OnClickListener {
    private TeamRankDetailFragment mCurrentFragment;
    private TeamRankDetailFragment mDjFragment;
    private TextView mDjTv;
    private View mDjView;
    private TeamRankDetailFragment mFjFragment;
    private TextView mFjTv;
    private View mFjView;
    private TeamRankDetailFragment mXjFragment;
    private TextView mXjTv;
    private View mXjView;
    private TeamRankDetailFragment mYcFragment;
    private TextView mYcTv;
    private View mYcView;
    private TeamRankDetailFragment mYjFragment;
    private TextView mYjTv;
    private View mYjView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView((int) R.layout.activity_team_rank);
        Window window = getWindow();
        initView();
        initData();
    }

    private void initView() {
        this.mYjTv = (TextView) findViewById(R.id.tv_yj);
        this.mYjView = findViewById(R.id.view_yj);
        this.mDjTv = (TextView) findViewById(R.id.tv_dj);
        this.mDjView = findViewById(R.id.view_dj);
        this.mYcTv = (TextView) findViewById(R.id.tv_yc);
        this.mYcView = findViewById(R.id.view_yc);
        this.mXjTv = (TextView) findViewById(R.id.tv_xj);
        this.mXjView = findViewById(R.id.view_xj);
        this.mFjTv = (TextView) findViewById(R.id.tv_fj);
        this.mFjView = findViewById(R.id.view_fj);
        findViewById(R.id.rl_yj).setOnClickListener(this);
        findViewById(R.id.rl_dj).setOnClickListener(this);
        findViewById(R.id.rl_yc).setOnClickListener(this);
        findViewById(R.id.rl_xj).setOnClickListener(this);
        findViewById(R.id.rl_fj).setOnClickListener(this);
    }
    public void back(View targv) {
        finish();
    }


    private void initData() {
        this.mYjFragment = TeamRankDetailFragment.newInstance("yj");
        this.mDjFragment = TeamRankDetailFragment.newInstance("dj");
        this.mYcFragment = TeamRankDetailFragment.newInstance("yc");
        this.mXjFragment = TeamRankDetailFragment.newInstance("xj");
        this.mFjFragment = TeamRankDetailFragment.newInstance("fj");
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add((int) R.id.fl_container, this.mYjFragment);
        this.mCurrentFragment = this.mYjFragment;
        ft.commit();
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_dj:
                if (this.mDjFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mDjFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mDjFragment).commit();
                }
                this.mCurrentFragment = this.mDjFragment;
                setTabStatus(R.id.rl_dj);
                return;
            case R.id.rl_fj:
                if (this.mFjFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mFjFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mFjFragment).commit();
                }
                this.mCurrentFragment = this.mFjFragment;
                setTabStatus(R.id.rl_fj);
                return;
            case R.id.rl_xj:
                if (this.mXjFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mXjFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mXjFragment).commit();
                }
                this.mCurrentFragment = this.mXjFragment;
                setTabStatus(R.id.rl_xj);
                return;
            case R.id.rl_yc:
                if (this.mYcFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mYcFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mYcFragment).commit();
                }
                this.mCurrentFragment = this.mYcFragment;
                setTabStatus(R.id.rl_yc);
                return;
            case R.id.rl_yj:
                if (this.mYjFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mYjFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mYjFragment).commit();
                }
                this.mCurrentFragment = this.mYjFragment;
                setTabStatus(R.id.rl_yj);
                return;
            default:
                return;
        }
    }

    private void setTabStatus(int id) {
        switch (id) {
            case R.id.rl_dj:
                this.mYjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDjTv.setTextColor(getResources().getColor(R.color.red));
                this.mXjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mFjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYcTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mFjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDjView.setBackgroundColor(getResources().getColor(R.color.red));
                this.mYcView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mXjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            case R.id.rl_fj:
                this.mYjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mXjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mFjTv.setTextColor(getResources().getColor(R.color.red));
                this.mYcTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mFjView.setBackgroundColor(getResources().getColor(R.color.red));
                this.mDjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mYcView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mXjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            case R.id.rl_xj:
                this.mYjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mXjTv.setTextColor(getResources().getColor(R.color.red));
                this.mFjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYcTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mFjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mYcView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mXjView.setBackgroundColor(getResources().getColor(R.color.red));
                return;
            case R.id.rl_yc:
                this.mYjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mXjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mFjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYcTv.setTextColor(getResources().getColor(R.color.red));
                this.mYjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mFjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mYcView.setBackgroundColor(getResources().getColor(R.color.red));
                this.mXjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            case R.id.rl_yj:
                this.mYjTv.setTextColor(getResources().getColor(R.color.red));
                this.mDjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mXjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mFjTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYcTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mYjView.setBackgroundColor(getResources().getColor(R.color.red));
                this.mFjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mYcView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mXjView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            default:
                return;
        }
    }
}